<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="最近做毕设的时候发现每次都需要输入命令启动 mongo 和 redis，还有一些爬虫和后台接口。感觉很麻烦，为什么不用 windows 上类似 shell 的 bat 语法写一个部署工具呢？ 截图   注：图中所用软件为丑陋 cmd 的替换品 cmder 不多多说了，直接上代码吧，bat 语法大家可以自己搜索下。 主进程 start.bat12345678910111213141516171819">
<meta name="keywords" content="windows,毕设">
<meta property="og:type" content="article">
<meta property="og:title" content="如何使用windows bat编写一个快速启动工具">
<meta property="og:url" content="https://andyliwr.github.io/2017/03/30/cmd_command/index.html">
<meta property="og:site_name" content="月光倾城的代码小屋">
<meta property="og:description" content="最近做毕设的时候发现每次都需要输入命令启动 mongo 和 redis，还有一些爬虫和后台接口。感觉很麻烦，为什么不用 windows 上类似 shell 的 bat 语法写一个部署工具呢？ 截图   注：图中所用软件为丑陋 cmd 的替换品 cmder 不多多说了，直接上代码吧，bat 语法大家可以自己搜索下。 主进程 start.bat12345678910111213141516171819">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://img.blog.csdn.net/20170330195438160">
<meta property="og:image" content="http://img.blog.csdn.net/20170330195452051">
<meta property="og:image" content="http://img.blog.csdn.net/20170330195504944">
<meta property="og:image" content="http://img.blog.csdn.net/20170330195143921">
<meta property="og:updated_time" content="2020-01-15T06:30:09.116Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="如何使用windows bat编写一个快速启动工具">
<meta name="twitter:description" content="最近做毕设的时候发现每次都需要输入命令启动 mongo 和 redis，还有一些爬虫和后台接口。感觉很麻烦，为什么不用 windows 上类似 shell 的 bat 语法写一个部署工具呢？ 截图   注：图中所用软件为丑陋 cmd 的替换品 cmder 不多多说了，直接上代码吧，bat 语法大家可以自己搜索下。 主进程 start.bat12345678910111213141516171819">
<meta name="twitter:image" content="http://img.blog.csdn.net/20170330195438160">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>如何使用windows bat编写一个快速启动工具</title>
    <!-- styles -->
    <link rel="stylesheet" href="/css/style.css">
    <!-- persian styles -->
    
      <link rel="stylesheet" href="/css/rtl.css">
    
    <!-- rss -->
    
    
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2017/04/05/html_auto_height/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2017/03/30/friddle_debug_online_code/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2017/03/30/cmd_command/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2017/03/30/cmd_command/&text=如何使用windows bat编写一个快速启动工具"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2017/03/30/cmd_command/&is_video=false&description=如何使用windows bat编写一个快速启动工具"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=如何使用windows bat编写一个快速启动工具&body=Check out this article: https://andyliwr.github.io/2017/03/30/cmd_command/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2017/03/30/cmd_command/&name=如何使用windows bat编写一个快速启动工具&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#截图"><span class="toc-number">1.</span> <span class="toc-text">截图</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#主进程-start-bat"><span class="toc-number">2.</span> <span class="toc-text">主进程 start.bat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#启动-redis-和-mongo-startMongoAndRedis-bat"><span class="toc-number">3.</span> <span class="toc-text">启动 redis 和 mongo startMongoAndRedis.bat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#启动后端接口-startApi"><span class="toc-number">4.</span> <span class="toc-text">启动后端接口 startApi</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#启动爬虫-startBdReptile-bat"><span class="toc-number">5.</span> <span class="toc-text">启动爬虫 startBdReptile.bat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#踩的一些坑"><span class="toc-number">6.</span> <span class="toc-text">踩的一些坑</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#传送门："><span class="toc-number">7.</span> <span class="toc-text">传送门：</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        如何使用windows bat编写一个快速启动工具
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">月光倾城的代码小屋</span>
      </span>
      
    <div class="postdate">
        <time datetime="2017-03-30T19:58:08.000Z" itemprop="datePublished">2017-03-30</time>
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/windows/">windows</a>, <a class="tag-link" href="/tags/毕设/">毕设</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <p>最近做毕设的时候发现每次都需要输入命令启动 mongo 和 redis，还有一些爬虫和后台接口。感觉很麻烦，为什么不用 windows 上类似 shell 的 bat 语法写一个部署工具呢？</p>
<h4 id="截图"><a href="#截图" class="headerlink" title="截图"></a>截图</h4><p><img src="http://img.blog.csdn.net/20170330195438160" alt="主界面"></p>
<p><img src="http://img.blog.csdn.net/20170330195452051" alt="启动mongo"></p>
<p><img src="http://img.blog.csdn.net/20170330195504944" alt="console"></p>
<p>注：图中所用软件为丑陋 cmd 的替换品 <a href="https://github.com/cmderdev/cmder/releases/" target="_blank" rel="noopener">cmder</a></p>
<p>不多多说了，直接上代码吧，bat 语法大家可以自己搜索下。</p>
<h4 id="主进程-start-bat"><a href="#主进程-start-bat" class="headerlink" title="主进程 start.bat"></a>主进程 <code>start.bat</code></h4><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"><span class="built_in">echo</span> 欢迎使用FollowHeart自动化工具，<span class="variable">%username%</span> ....</span><br><span class="line"><span class="built_in">echo</span> 使用之前请确保mongo和redis安装地址都已经加入到到了系统环境变量里</span><br><span class="line"><span class="built_in">ECHO</span>.</span><br><span class="line">:: 公共参数设置 <span class="built_in">start</span></span><br><span class="line"><span class="keyword">If</span> <span class="variable">%username%</span> == Andyliwr (</span><br><span class="line">  :: 记得改成ANDYLIWRTHS</span><br><span class="line">  <span class="built_in">echo</span> <span class="variable">%computername%</span></span><br><span class="line">  <span class="keyword">If</span> <span class="variable">%computername%</span> == ANDYLIWRTHS (</span><br><span class="line">     <span class="built_in">set</span> projectAddr=C:\Users\Andyliwr\Documents\graduationDesign</span><br><span class="line">     <span class="built_in">set</span> mongoDbPath=D:\mongo\data</span><br><span class="line">     <span class="built_in">set</span> mongoLogPath=D:\mongo\log\mongo.log</span><br><span class="line">     <span class="built_in">set</span> mongoConfAddr=D:\mongo\mongod.conf</span><br><span class="line">     <span class="built_in">set</span> redisConfAddr=D:\redis\redis.windows.conf</span><br><span class="line">  ) <span class="keyword">Else</span> (</span><br><span class="line">     <span class="built_in">set</span> projectAddr=C:\Users\Andyliwr\Documents\graduationDesign</span><br><span class="line">     <span class="built_in">set</span> mongoDbPath=E:\mongo_install\data</span><br><span class="line">     <span class="built_in">set</span> mongoLogPath=E:\mongo_install\log\mongo.log</span><br><span class="line">     <span class="built_in">set</span> mongoConfAddr=E:\mongo_install\mongod.conf</span><br><span class="line">     <span class="built_in">set</span> redisConfAddr=E:\redis\redis.windows.conf</span><br><span class="line">  )</span><br><span class="line">) <span class="keyword">Else</span> (</span><br><span class="line">  <span class="keyword">If</span> <span class="variable">%username%</span> == Greenovia (</span><br><span class="line">     <span class="built_in">set</span> projectAddr=G:\git项目\graduationDesign</span><br><span class="line">     <span class="built_in">set</span> mongoDbPath=F:\mongo\data</span><br><span class="line">     <span class="built_in">set</span> mongoLogPath=F:\mongo\log\mongo.log</span><br><span class="line">     <span class="built_in">set</span> mongoConfAddr=F:\mongo\mongod.conf</span><br><span class="line">     <span class="built_in">set</span> redisConfAddr=F:\redis\redis.windows.conf</span><br><span class="line">  ) <span class="keyword">Else</span> (</span><br><span class="line">     <span class="built_in">echo</span> 请使用文本编辑器打开<span class="built_in">start</span>.bar手动配置地址：</span><br><span class="line">     :: 请输入你当前的FollowHeart根目录地址:</span><br><span class="line">     <span class="built_in">set</span> projectAddr=xxx</span><br><span class="line">     :: 请输入mongo数据存储地址(类似F:\mongo\data):</span><br><span class="line">     <span class="built_in">set</span> mongoDbPath=xxx</span><br><span class="line">     :: 请输入mongo日志文件地址(类似F:\mongo\log\mongo.log):</span><br><span class="line">     <span class="built_in">set</span> mongoLogPath=xxx</span><br><span class="line">     :: 请输入mongo配置文件的地址(类似F:\mongo\mongod.conf):</span><br><span class="line">     <span class="built_in">set</span> mongoConfAddr=xxx</span><br><span class="line">     :: 请输入mongo配置文件的地址(类似F:\redis\redis.windows.conf):</span><br><span class="line">     <span class="built_in">set</span> redisConfAddr=xxx</span><br><span class="line">  )</span><br><span class="line">)</span><br><span class="line">:: 公共参数设置 end</span><br><span class="line">::清屏操作</span><br><span class="line"><span class="comment">rem cls</span></span><br><span class="line"><span class="keyword">goto</span> <span class="built_in">start</span></span><br><span class="line">:<span class="built_in">start</span></span><br><span class="line">    <span class="built_in">echo</span> --------------------------------------------------</span><br><span class="line">    <span class="built_in">echo</span> --                FollowHeart部署               --</span><br><span class="line">    <span class="built_in">echo</span> --  <span class="number">1</span>.启动mongo和redis                          --</span><br><span class="line">    <span class="built_in">echo</span> --  <span class="number">2</span>.启动接口                                  --</span><br><span class="line">    <span class="built_in">echo</span> --  <span class="number">3</span>.排行榜爬虫                                --</span><br><span class="line">    <span class="built_in">echo</span> --  <span class="number">4</span>.百度贴吧榜爬虫                            --</span><br><span class="line">    <span class="built_in">echo</span> --  <span class="number">5</span>.启动微信小城程序                          --</span><br><span class="line">    <span class="built_in">echo</span> --  <span class="number">6</span>.新环境部署(该选项操作完成后会自动部署)    --</span><br><span class="line">    <span class="built_in">echo</span> --  <span class="number">7</span>.END                                       --</span><br><span class="line">    <span class="built_in">echo</span> --------------------------------------------------</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">echo</span> (请输入数字选择操作命令)</span><br><span class="line">    <span class="built_in">set</span> /p ans=</span><br><span class="line">    <span class="keyword">if</span> <span class="variable">%ans%</span>==<span class="number">1</span> <span class="keyword">goto</span> startMongoAndRedis</span><br><span class="line">    <span class="keyword">if</span> <span class="variable">%ans%</span>==<span class="number">2</span> <span class="keyword">goto</span> startApi</span><br><span class="line">    <span class="keyword">if</span> <span class="variable">%ans%</span>==<span class="number">3</span> <span class="keyword">goto</span> startRankReptile</span><br><span class="line">    <span class="keyword">if</span> <span class="variable">%ans%</span>==<span class="number">4</span> <span class="keyword">goto</span> startBdReptile</span><br><span class="line">    <span class="keyword">if</span> <span class="variable">%ans%</span>==<span class="number">5</span> <span class="keyword">goto</span> startWechat</span><br><span class="line">    <span class="keyword">if</span> <span class="variable">%ans%</span>==<span class="number">6</span> <span class="keyword">goto</span> deploy</span><br><span class="line">    <span class="keyword">if</span> <span class="variable">%ans%</span>==<span class="number">7</span> <span class="keyword">goto</span> END</span><br><span class="line">:startMongoAndRedis</span><br><span class="line">    <span class="built_in">echo</span> <span class="built_in">echo</span> 正在启动redis和mongo...</span><br><span class="line">    <span class="built_in">start</span> "启动mongo和redis" startMongoAndRedis.bat <span class="variable">%redisConfAddr%</span> <span class="variable">%mongoLogPath%</span> <span class="variable">%mongoDbPath%</span></span><br><span class="line">    <span class="built_in">echo</span> <span class="built_in">echo</span> 已经启动redis和mongo...</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="keyword">goto</span> <span class="built_in">start</span></span><br><span class="line">:startApi</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">echo</span> 正在启动后端接口，请确保在启动接口之前已经执行过<span class="number">1</span>了...</span><br><span class="line">    <span class="built_in">start</span> "启动后端接口" startApi.bat <span class="variable">%projectAddr%</span></span><br><span class="line">    <span class="built_in">echo</span> 后端接口启动成功...</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="keyword">goto</span> <span class="built_in">start</span></span><br><span class="line">:startBdReptile</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">echo</span> 正在运行百度贴吧爬虫...</span><br><span class="line">    <span class="built_in">start</span> "启动百度贴吧爬虫" startBdReptile.bat <span class="variable">%projectAddr%</span></span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="keyword">goto</span> <span class="built_in">start</span></span><br><span class="line">:startRankReptile</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">echo</span> 正在运行排行榜爬虫...</span><br><span class="line">    <span class="built_in">start</span> "启动百度贴吧爬虫" startRankReptile.bat <span class="variable">%projectAddr%</span></span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="keyword">goto</span> <span class="built_in">start</span></span><br><span class="line">:startWechat</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">echo</span> 正在启动微信小程序...</span><br><span class="line">   <span class="built_in">start</span> "启动微信小程序" startWechat.bat <span class="variable">%projectAddr%</span></span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="keyword">goto</span> <span class="built_in">start</span></span><br><span class="line">:deploy</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">echo</span> ----执行static项目解压操作----</span><br><span class="line">    :: 执行的逻辑命令--为bat文件传参</span><br><span class="line">    <span class="built_in">start</span> static.bat <span class="variable">%uatPath%</span> <span class="variable">%sourcePath%</span> <span class="variable">%sourceDisk%</span></span><br><span class="line">    <span class="built_in">echo</span> ----static项目解压操作完成----</span><br><span class="line">    <span class="keyword">goto</span> <span class="built_in">start</span></span><br><span class="line">:END</span><br><span class="line">    <span class="built_in">ECHO</span>.</span><br><span class="line">    <span class="built_in">echo</span> 退出批处理操作</span><br><span class="line"><span class="built_in">pause</span></span><br></pre></td></tr></table></figure>
<h4 id="启动-redis-和-mongo-startMongoAndRedis-bat"><a href="#启动-redis-和-mongo-startMongoAndRedis-bat" class="headerlink" title="启动 redis 和 mongo startMongoAndRedis.bat"></a>启动 redis 和 mongo <code>startMongoAndRedis.bat</code></h4><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"><span class="built_in">echo</span> <span class="built_in">echo</span> 正在启动redis...</span><br><span class="line"><span class="built_in">set</span> redisConfAddr=%<span class="number">1</span></span><br><span class="line"><span class="built_in">set</span> mongoLogPath=%<span class="number">2</span></span><br><span class="line"><span class="built_in">set</span> mongoDbPath=%<span class="number">3</span></span><br><span class="line">redis-server.exe <span class="variable">%redisConfAddr%</span> --loglevel verbose</span><br><span class="line"><span class="keyword">If</span> <span class="keyword">errorlevel</span> <span class="number">1</span> (</span><br><span class="line">    <span class="built_in">echo</span> Redis已经启动，请打开新的窗口输入redis-cli.exe开启你的管理吧...</span><br><span class="line">) <span class="keyword">Else</span> (</span><br><span class="line">    <span class="built_in">echo</span> Redis启动失败，请检查你配置的目录是否正确...</span><br><span class="line">)</span><br><span class="line"><span class="built_in">ECHO</span>.</span><br><span class="line"><span class="built_in">echo</span> 正在启动Mongo...</span><br><span class="line">mongod.exe --logpath=<span class="variable">%mongoLogPath%</span> --dbpath=<span class="variable">%mongoDbPath%</span> --journal --maxConns <span class="number">20000</span></span><br><span class="line"><span class="built_in">echo</span> <span class="variable">%errorlevel%</span></span><br><span class="line"><span class="keyword">If</span> <span class="keyword">errorlevel</span> <span class="number">1</span> (</span><br><span class="line">    <span class="built_in">echo</span> Mongo已经启动，请打开新的窗口输入mongo开启你的管理吧...</span><br><span class="line">) <span class="keyword">Else</span> (</span><br><span class="line">    <span class="built_in">echo</span> Mongo启动失败，请检查你配置的目录是否正确...</span><br><span class="line">)</span><br></pre></td></tr></table></figure>
<h4 id="启动后端接口-startApi"><a href="#启动后端接口-startApi" class="headerlink" title="启动后端接口 startApi"></a>启动后端接口 <code>startApi</code></h4><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"><span class="built_in">set</span> projectAddr=%<span class="number">1</span></span><br><span class="line"><span class="built_in">echo</span> 正在启动后端接口，请确保在启动接口之前已经执行过<span class="number">1</span>了...</span><br><span class="line"><span class="built_in">cd</span> <span class="variable">%projectAddr%</span>/api</span><br><span class="line"><span class="keyword">If</span> <span class="keyword">exist</span> node_modules (</span><br><span class="line">   <span class="built_in">echo</span> "node包已安装..."</span><br><span class="line">) <span class="keyword">Else</span> (</span><br><span class="line">    cnpm install</span><br><span class="line">)</span><br><span class="line">node .</span><br><span class="line"><span class="keyword">If</span> <span class="keyword">errorlevel</span> <span class="number">1</span> (</span><br><span class="line">    <span class="built_in">echo</span> 后端接口已经启动，请在浏览器中打开localhost:<span class="number">3000</span>/explorer来查看吧...</span><br><span class="line">) <span class="keyword">Else</span> (</span><br><span class="line">    <span class="built_in">echo</span> 后端接口启动失败...</span><br><span class="line">)</span><br></pre></td></tr></table></figure>
<h4 id="启动爬虫-startBdReptile-bat"><a href="#启动爬虫-startBdReptile-bat" class="headerlink" title="启动爬虫 startBdReptile.bat"></a>启动爬虫 startBdReptile.bat</h4><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"><span class="built_in">set</span> projectAddr=%<span class="number">1</span></span><br><span class="line"><span class="built_in">echo</span> 正在运行百度贴吧爬虫...</span><br><span class="line"><span class="built_in">cd</span> <span class="variable">%projectAddr%</span>/reptile</span><br><span class="line"><span class="keyword">If</span> <span class="keyword">exist</span> node_modules (</span><br><span class="line">   <span class="built_in">echo</span> node包已安装...</span><br><span class="line">) <span class="keyword">Else</span> (</span><br><span class="line">   cnpm install</span><br><span class="line">)</span><br><span class="line">node networkReptile.js</span><br></pre></td></tr></table></figure>
<h4 id="踩的一些坑"><a href="#踩的一些坑" class="headerlink" title="踩的一些坑"></a>踩的一些坑</h4><p>创建 bat 文件最好先使用系统自带的记事本创建一个文本文件，然后在另存为 bat 文件，并且设置编码为 ASNI，不然很容易中文乱码的。包括使用一些主流的编辑器如 sublime 都会出现这种问题。博主建议使用 sublime 编辑 bat 文件，毕竟有语法高亮和快捷键，写起来很方便。然后编写完了别保存直接复制到记事本中保存，这样能避免中文乱码。如果你有更好的方法，不妨在评论中回复博主。<br><img src="http://img.blog.csdn.net/20170330195143921" alt="保存编码的问题"></p>
<h4 id="传送门："><a href="#传送门：" class="headerlink" title="传送门："></a>传送门：</h4><ol>
<li><a href="http://www.imooc.com/article/8283" target="_blank" rel="noopener">小白都能看懂的 windows 常用 bat 批处理命令</a></li>
<li><a href="http://www.360doc.com/content/11/0804/10/4127803_137849318.shtml" target="_blank" rel="noopener">Bat 语法命令</a></li>
</ol>

  </div>
  <div class="statement">
    <hr>  
    1. 如果本文帮到了您，不妨点一下右上角的”<i class="fas fa-share-alt"></i>“按钮。<br>
    2. 除非注明，本博文章均为原创，转载请以链接形式标明本文地址。<br>
    3. 如果你有任何疑问，欢迎发送邮件到我的邮箱<a href="mailto:andyliwr@outlook.com">andyliwr@outlook.com<br>
  </div>
</article>


    <div class="blog-post-comments">
        <div id="gitalk_thread">
            <noscript>加载评论需要在浏览器启用 JavaScript 脚本支持。</noscript>
        </div>
    </div>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#截图"><span class="toc-number">1.</span> <span class="toc-text">截图</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#主进程-start-bat"><span class="toc-number">2.</span> <span class="toc-text">主进程 start.bat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#启动-redis-和-mongo-startMongoAndRedis-bat"><span class="toc-number">3.</span> <span class="toc-text">启动 redis 和 mongo startMongoAndRedis.bat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#启动后端接口-startApi"><span class="toc-number">4.</span> <span class="toc-text">启动后端接口 startApi</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#启动爬虫-startBdReptile-bat"><span class="toc-number">5.</span> <span class="toc-text">启动爬虫 startBdReptile.bat</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#踩的一些坑"><span class="toc-number">6.</span> <span class="toc-text">踩的一些坑</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#传送门："><span class="toc-number">7.</span> <span class="toc-text">传送门：</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2017/03/30/cmd_command/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2017/03/30/cmd_command/&text=如何使用windows bat编写一个快速启动工具"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2017/03/30/cmd_command/&is_video=false&description=如何使用windows bat编写一个快速启动工具"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=如何使用windows bat编写一个快速启动工具&body=Check out this article: https://andyliwr.github.io/2017/03/30/cmd_command/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2017/03/30/cmd_command/&title=如何使用windows bat编写一个快速启动工具"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2017/03/30/cmd_command/&name=如何使用windows bat编写一个快速启动工具&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Dikang Li
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
</body>
</html>
<!-- styles -->
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">
<link rel="stylesheet" href="/lib/fancybox/jquery.fancybox.css">

<link rel="stylesheet" href="https://file.lantingshucheng.com/blog/v3/static/styles/gitalk.css">


<!-- jquery -->
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>
<script src="/lib/fancybox/jquery.fancybox.pack.js"></script>

<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/md5.js"></script>
<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/gitalk.min.js"></script>

<script src="/js/main.js"></script>
<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?7851ca7a86be957be994acb77639a5be";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


  <script type="text/javascript">
    window.onload = function(){
      if (window.location.href.indexOf('andyliwr.github.io') > -1) {
        var gitalk = new Gitalk({
          clientID: 'ad6f70df0c70d2b715f9',
          clientSecret: '40384bee244c1e17dd7c37733d21e9ef669e969c',
          repo: 'Andyliwr.github.io',
          owner: 'Andyliwr',
          admin: ['Andyliwr'],
          id: md5(location.pathname),
          distractionFreeMode: 'true'
        })
        gitalk.render('gitalk_thread')
      }
    }
  </script>


